/*
 * @Author: your name
 * @Date: 2020-07-13 10:52:32
 * @LastEditTime: 2021-01-20 17:34:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Editt
 * @FilePath: \myReposCode\Verification\callbackFunction.cpp
 */
#include <iostream>
#include <string>
#include <cstddef>

using namespace std;

class MyStruct
{
public:
    int a;
    double b;
};

// 利用回调函数，实现打印任意类型的数据，回调的工作：交给用户去做
void printAnyData(void *data, void (*callBack)(void *))
{
    callBack(data);
}

void myCallBack(void *data)
{
    MyStruct *pdata = static_cast<MyStruct *>(data);
    cout << "a = " << pdata->a << endl;
    cout << "b = " << pdata->b << endl;
}

void test()
{
    MyStruct mst = {2, 2.3};
    printAnyData(&mst, myCallBack);
}


int main(int argc, char **argv)
{
    test();    
    return 0;
}